<?php

class FiltersModule extends fvModule {

    function __construct () {
        $moduleName = strtolower(substr(__CLASS__, 0, -6));

        parent::__construct(fvSite::$fvConfig->get("modules.{$moduleName}.smarty.template"), 
                            fvSite::$fvConfig->get("modules.{$moduleName}.smarty.compile"), 
                            fvSite::$Layoult);
    }

    function showIndex() {
        if (!fvRequest::getInstance()->hasRequestParameter("page")) {
            if (fvSite::$fvSession->is_set(fvRequest::getInstance()->getRequestParameter("requestURL")."/page")) {
                fvRequest::getInstance()->putRequestParameter("page",
                    (int)fvSite::$fvSession->get(fvRequest::getInstance()->getRequestParameter("requestURL")."/page"));
            } 
        } else {
            fvSite::$fvSession->set(fvRequest::getInstance()->getRequestParameter("requestURL")."/page", 
                fvRequest::getInstance()->getRequestParameter("page"));
        }

        if (substr($requestURL = fvRequest::getInstance()->getRequestParameter("requestURL"), 0, 1) == "/") {
            $requestURL = substr($requestURL, 1);
        }
        
        $Filters = FilterManager::getInstance()->getAll();
        
        $pager = new fvPager(null, $Filters);
        $this->__assign('Filters', $pager->paginate());
        return $this->__display('filter_list.tpl');    
    }

    function showEdit() {
        $request = fvRequest::getInstance();
        if (!$Filter = FilterManager::getInstance()->getByPk($request->getRequestParameter('id'))) {
            $Filter = new Filter();
        }
		
        $this->__assign(array(
            'Filter' => $Filter,
        ));
        return $this->__display('filter_edit.tpl');
        
    }
    
}

?>
